package trytest

import (
	"math/rand"

	"github.com/pkg/profile"
)

// 耗时的函数
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

func randomString(n int) string {
	b := make([]byte, n)
	for i := range b {
		b[i] = letterBytes[rand.Intn(len(letterBytes))]
	}
	return string(b)
}

// 耗时的函数用于性能测试
func ExhaustConcat(n int) string {
	s := ""
	for i := 0; i < n; i++ {
		s += randomString(n)
	}
	return s
}
func TestProfit() {
	// 执行完毕后, 使用go tool pprof 来解析
	defer profile.Start(profile.MemProfile, profile.MemProfileRate(1)).Stop()
	// go tool pprof  C:\Users\anan\AppData\Local\Temp\profile367424215\mem.pprof
	// go tool pprof --http=localhost:9999 C:\Users\anan\AppData\Local\Temp\profile367424215\mem.pprof
	ExhaustConcat(10)
}
